package com.example.mybatisplusdemo.interceptor;

import org.apache.ibatis.plugin.*;

import java.sql.Connection;
import java.sql.Statement;
import java.util.Properties;

/**
 * @author H
 * @date 2023/1/2
 */
// 定义拦截签名
@Intercepts({
                @Signature(
                        type = Statement.class,
                        method = "prepare",
                        args = {Connection.class, Integer.class})
})
public class MyPlugin implements Interceptor {

    Properties properties = null;

    /**
     * 拦截方法逻辑
     * @param invocation
     * @return
     * @throws Throwable
     */
    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        System.out.println("插件拦截方法");
        return invocation.proceed();
    }

    /**
     * 生成mybatis拦截器代理对象
     * @param target
     * @return
     */
    @Override
    public Object plugin(Object target) {
        return Plugin.wrap(target, this);
    }

    /**
     * 设置插件属性
     * @param properties
     */
    @Override
    public void setProperties(Properties properties) {
        this.properties = properties;
    }
}
